Discussion討論區-2 << 
Previous Next >> Conditionals有條件的
Modular arithmetic the modulus operator模塊化算術模運算符
We have been doing arithmetic (addition, subtraction, multiplication, division) since elementary school, and often it is useful for us to find not the answer to a division problem but the remainder when we do a division operation. This operation is called the “modulus operation.” For example, when I divide 5 by 3, the remainder is 2, and the sentence reads like this: “5 modulo 3 is 2.”
In the Python shell:
>>> 5 % 3
2
>>> 6 % 3
0
>>> 7 % 3
1
The % sign is exactly the modulus operator.
從小學開始,我們就一直在進行算術運算(加,減,乘,除),這對於我們尋找除法問題不是答案,而是對除法運算的其餘部分有用。該操作稱為“模運算”。例如,當我將5除以3時,餘數為2,句子的內容如下:“ 5模3為2”。
在Python Shell中:
  
>>> 5 % 3
2
>>> 6 % 3
0
>>> 7 % 3
1
該%標誌是完全模運算符。
Discussion討論區-2 << 
Previous Next >> Conditionals有條件的